#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
using namespace std;

const int MAXN = 100000;
int next[MAXN][256];
int f[MAXN], g[MAXN];
int c[256];
vector<int> v;

void init() {
    memset(next, 0, sizeof(next));
    memset(f, 0, sizeof(f));
    memset(g, 0, sizeof(g));
    v.clear();
}

void insert(const char *str) {
    int len = strlen(str);
    int p = 0;
    for (int i = 0; i < len; i++) {
        if (next[p][str[i]] == 0) {
            v.push_back(str[i]);
            next[p][str[i]] = v.size() - 1;
        }
        p = next[p][str[i]];
    }
    g[p]++;
}

void build_ac() {
    int m = v.size();
    for (int i = 0; i < m; i++) {
        c[v[i]] = i;
    }
    int p = 0;
    for (int i = 0; i < m; i++) {
        int q = 0;
        for (int j = 0; j < 256; j++) {
            if (next[p][j] == 0) {
                next[p][j] = q;
            } else {
                int t = next[p][j];
                next[p][j] = q;
                if (g[t] < g[q]) {
                    swap(v[t], v[q]);
                }
                q = next[q][v[t]];
            }
        }
        p = next[p][v[i]];
    }
}

int query(const char *str) {
    int len = strlen(str);
    int p = 0;
    for (int i = 0; i < len; i++) {
        p = next[p][str[i]];
    }
    return g[p];
}

int main() {
    init();
    char str[] = "a";
    insert(str);
    build_ac();
    cout << "Number of occurrences: " << query(str) << endl;
    return 0;
}
